package com.itheima.controller;

import com.itheima.anno.Log;
import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.dto.EmpDto;
import com.itheima.dto.EmpPasswprdDto;
import com.itheima.dto.EmpQueryDto;
import com.itheima.pojo.Emp;
import com.itheima.service.EmpService;
import com.itheima.vo.EmpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/emps")
@RestController
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping
    public R pageQuery(EmpQueryDto dto) {
        PageBean pageBean = empService.pageQuery(dto);
        return R.ok(pageBean);
    }

    @GetMapping("/list")
    public R selectAll() {
        List<Emp> emps = empService.selectAll();
        return R.ok(emps);
    }

    @Log
    @PostMapping
    public R insert(@RequestBody EmpDto empDto) {
        empService.insert(empDto);
        return R.ok();
    }

    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        EmpVo vo = empService.getById(id);
        return R.ok(vo);
    }

    @Log
    @PutMapping
    public R update(@RequestBody EmpDto dto) {
        empService.update(dto);
        return R.ok();
    }
    @Log
    @DeleteMapping
    public R delete(@RequestParam List<Integer> ids) {
        empService.delete(ids);
        return R.ok();
    }
    @PutMapping("/changePassword")
    public R changePassword(@RequestBody EmpPasswprdDto dto) {
        empService.changePassword(dto);
        return R.ok();
    }
}



